package org.dreamwork.jasmine2.web.controls;

import org.dreamwork.jasmine2.events.EventException;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by IntelliJ IDEA.
 * User: seth
 * Date: 2009-7-28
 * Time: 15:28:31
 */
public class UserControl extends Page {
    public UserControl () {
        htmlTagName = "div";
    }

    @Override
    public boolean isPostback () {
        if (parent != null) return parent.getPage ().isPostback ();
        return super.isPostback ();
    }

    @Override
    public void render (PrintWriter writer) throws IOException, EventException {
        super.render (writer);    //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    public void registerClientScriptBlock (Class clazz, String script) {
        if (this != page)
            page.registerClientScriptBlock (clazz, script);
        else
            super.registerClientScriptBlock (clazz, script);
    }

    @Override
    public void registerStyleFile (Class clazz, String style) {
        if (this != page)
            page.registerStyleFile (clazz, style);
        else
            super.registerStyleFile (clazz, style);
    }

    protected String getIdPrefix () {
        String id = getId ();
        if (id == null || id.startsWith ("_auto_")) return "";
        return id + "_";
    }

    @Override
    public Page getPage () {
        if (parent != null) return parent.getPage ();
        return super.getPage ();
    }
}